import React, { Component } from 'react'
import {Route, withRouter} from "react-router";
import {PRIVATE_ROUTE} from "../../../../route.constants";
import { List } from 'antd-mobile'
import axios from "../../../../http";


 class NoteMenu extends Component {
    constructor(props) {

        super(props);

        this.state={};

    }
    componentDidMount() {
        this.loadData();
    }
    getUserMenu=(menuList:any,code)=>{
        for(let i=0;i<menuList.length;i++){
            if(menuList[i].nameEn===code){
                return menuList[i];
            }
        }
        return null;
    }
    getChildrenByParentId=(menuList:any,parentId)=>{
        let retVal=new Array();
        for(let i=0;i<menuList.length;i++){
            if(menuList[i].pId===parentId){
                retVal.push(menuList[i]);
            }
        }
        return retVal;
    }
    loadData=()=>{

        axios.post('api/core/access/resources/getUserMenuZtreeJson',{headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
            .then((response)=>{

                let  data:any=response.data.data;
                

                let menuNoteWork=this.getUserMenu(data,'APP_OA_NOTE');

                let menuNoteSchedules=this.getChildrenByParentId(data,menuNoteWork.id);

                this.setState({menuNoteSchedules:menuNoteSchedules});

            }).catch(function (error) {
                console.log(error);
            });

    }



    createSubMenu=()=>{
        return (this.state.menuNoteSchedules || []).map((item,index)=>{
            return [<List.Item key={index}  onClick={()=>{this.props.history.push('/note/'+PRIVATE_ROUTE[item.nameEn])}}>
                {item.nameZh}

            </List.Item>]
        })

    }
    render() {
        return (
            <>
               <List>
                    {this.createSubMenu()}
                </List>
            </>
        )
    }
}
export default withRouter(NoteMenu)